/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOS.DAOSADMINISTRACION;

import Entidades.EntidadesAdministracion.Roles;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author daniel
 */
@Stateless
@LocalBean
public class RolesDAos {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
  @PersistenceContext
    EntityManager em;
    public void crear(Roles r) {
        em.persist(r);
    }

    public void actualizar(Roles r) {
        em.merge(r);
    }

    public void borrar(Integer id) {
        Roles rol = em.find(Roles.class, id);
        em.remove(rol);
    }

    public void guardar(Roles r) {
        if (r.getIdRoles() == null) {
            crear(r);
        } else {
            actualizar(r);
        }
    }

    public List<Roles> BuscarTodosRoles() {
        return em.createNamedQuery("Roles.findAll", Roles.class).getResultList();
    }

    public List<Roles> BuscarRoles(String cadena) {
        return em.createNamedQuery("Roles.findByIdRoles", Roles.class)
                .setParameter("roles", cadena).getResultList();
    }
   
}
